/**
 * 
 */
package org.ssh2Maven.model.systemModel;

import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.ssh2Maven.model.systemModelUtility.SystemEnums;

/**
 * @author guangz
 *
 */
@Entity
@Table(name="tb_Sys_User")
public class SystemUser
{
	private int userId;
	private String userName;
	private SystemEnums.Sex sex;
	private String idCardNo;
	private String telPhoneNo;
	private Date birthday;
	private String loginId;
	private String password;
	private SystemEnums.Status userStatus;
	private String email;
	private Set<SystemRole> roles = new LinkedHashSet<SystemRole>();

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getUserId()
	{
		return userId;
	}

	public void setUserId(int userId)
	{
		this.userId = userId;
	}

	@Column(length=50,nullable=false)
	public String getUserName()
	{
		return userName;
	}

	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	@Enumerated(EnumType.ORDINAL)
	public SystemEnums.Sex getSex()
	{
		return sex;
	}

	public void setSex(SystemEnums.Sex sex)
	{
		this.sex = sex;
	}

	public String getIdCardNo()
	{
		return idCardNo;
	}

	@Column(length=20)
	public void setIdCardNo(String idCardNo)
	{
		this.idCardNo = idCardNo;
	}

	@Column(length=20)
	public String getTelPhoneNo()
	{
		return telPhoneNo;
	}

	public void setTelPhoneNo(String telPhoneNo)
	{
		this.telPhoneNo = telPhoneNo;
	}

	public Date getBirthday()
	{
		return birthday;
	}

	public void setBirthday(Date birthday)
	{
		this.birthday = birthday;
	}

	@Column(length=20,nullable=false, unique=true)
	public String getLoginId()
	{
		return loginId;
	}

	public void setLoginId(String loginId)
	{
		this.loginId = loginId;
	}

	@Column(length=20,nullable=false)
	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public SystemEnums.Status getUserStatus()
	{
		return userStatus;
	}

	public void setUserStatus(SystemEnums.Status userStatus)
	{
		this.userStatus = userStatus;
	}

	@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="tb_Sys_User_Role", joinColumns={@JoinColumn(name="userId")}, 
					inverseJoinColumns={@JoinColumn(name="roleId")})
	@OrderBy("id")
	public Set<SystemRole> getRoles()
	{
		return roles;
	}

	public void setRoles(Set<SystemRole> roles)
	{
		this.roles = roles;
	}

	@Column(length=30)
	public String getEmail()
	{
		return email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}
}
